﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class UserControl_XoaTk1 : System.Web.UI.UserControl
{
    private AdminBLL adminBLL;
    private Users user;

    protected void Page_Load(object sender, EventArgs e)
    {
        this.adminBLL = new AdminBLL();
    }

    protected void btnDisplay_Click(object sender, EventArgs e)
    {
        string username = this.txtUsername.Text.Trim();

        this.user = this.adminBLL.GetIUsers.GetUserByUsername(username);

        if (this.user != null)
        {
            UserProfiles userProfile = this.adminBLL.GetIUserProfiles.GetUserProfileOfUser(this.user);

            this.txtNames.Text = userProfile.Name;
            if (userProfile.Gender)
            {
                this.txtGender.Text = "Nam";
            }
            else
            {
                this.txtGender.Text = "Nữ";
            }

            this.txtDateBirth.Text = userProfile.DateBirth.ToString();
            this.txtPeople.Text = userProfile.People;

            List<Posts> listPosts = this.adminBLL.GetIPosts.GetListPostsOfUser(this.user);

            this.txtTotalArticle.Text = listPosts.Count.ToString();

            this.btnDeleteAccount.Enabled = true;

        }
    }

    protected void btnDeleteAccount_Click(object sender, EventArgs e)
    {
        this.user.Active = false;

        bool result = this.adminBLL.GetIUsers.UpdateUser(this.user);
        
    }
}